package com.alone.embedded.lucene.repository.query.wrapper;

import com.alone.embedded.lucene.util.LambdaUtil;
import com.alone.embedded.lucene.util.SerializableFunction;

/**
 * @author Alone
 * @date 2022/8/22 10:21 上午
 */
public class LambdaQueryWrapper<T> extends AbstractConditionQueryWrapper<T, SerializableFunction<T, ?>, LambdaQueryWrapper<T>> {

    @SafeVarargs
    @Override
    public final LambdaQueryWrapper<T> select(SerializableFunction<T, ?>... columns) {
        select(true, columns);
        return this;
    }

    @SafeVarargs
    @Override
    public final LambdaQueryWrapper<T> select(boolean condition, SerializableFunction<T, ?>... columns) {
        if (condition) {
            for (SerializableFunction<T, ?> column : columns) {
                selectFieldSet.add(columnToStr(column));
            }
        }
        return this;
    }

    @Override
    protected String columnToStr(SerializableFunction<T, ?> column) {
        return LambdaUtil.getFieldName(column);
    }
}
